<?php

class Core_View_Helper_ShowMore extends Zend_View_Helper_Abstract
{
	const MAX_WORDS = 41;

	public function showMore($content = '')
	{
		$content = str_replace('<p>', '', $content);
		$content = str_replace('</p>', '', $content);
		
		$data = explode(' ', $content);
		$string = '';
		$show_more = false;
		for ($i = 0; $i < sizeof($data); $i++)
		{
			
			$string .= $data[$i] . ' ';

			if ($i+1  == (sizeof($data)))
			{
				if($show_more)
				{
					$string .= "<a class='link_show_less' href='#'> &laquo; less</a>";
					$string .= '</div>';
				}
			}

			
			if ($i == self::MAX_WORDS && $i < sizeof($data))
			{
				$string .= '<a href="#" class="link_show_more"> &raquo; more</a> ';
				$show_more = true;
				$string .= '<div class="show_more" style="display:none">';
			}
		}


		return $string;
	}

}
